# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Eli Schwartz <eschwartz@archlinux.org>

pkgname=python-py7zr
_pyname=${pkgname#python-}
pkgver=0.20.5
pkgrel=2
pkgdesc='Pure python 7-zip library'
arch=(any)
url="https://github.com/miurahr/${_pyname}"
license=(LGPL)
_pydeps=(brotli
         brotlicffi
         psutil
         multivolumefile
         pybcj
         pycryptodomex
         pyppmd
         pyzstd
         texttable
         inflate64)
depends=(python
         "${_pydeps[@]/#/python-}")
optdepends=('python-zstandard: zstd compression')
makedepends=(python-{build,installer,wheel}
             python-setuptools-scm)
checkdepends=(p7zip
              pyannotate
              python-py-cpuinfo
              python-pytest-benchmark
              python-pytest-timeout)
_archive="$_pyname-$pkgver"
source=("https://files.pythonhosted.org/packages/source/${_pyname::1}/$_pyname/$_archive.tar.gz")
sha256sums=('6fb4889c0fa32581818a3366984083253585d6c794e82c3242b8a12d6aeaabd3')

prepare() {
	cd "$_archive"
	# Upstream setuptools version pinning is too aggressive for us.
	# It is also outdated because current versions have toml support is builtin.
	sed -i -E '/^requires /s#([a-z])[\[>][^"]*"#\1"#g' pyproject.toml
	sed -i -E '/setuptools/s#>.*##' setup.cfg
}

build() {
	cd "$_archive"
	python -m build -wn
}

check() {
	cd "$_archive"
	python -m pytest -rsx \
		--deselect tests/test_concurrent.py \
		--deselect tests/test_extra_codecs.py \
		-m 'not benchmark and not remote_data'
}

package() {
	cd "$_archive"
	python -m installer -d "$pkgdir" dist/*.whl
}
